package com.umeng.analytics.pro;

import java.nio.ByteBuffer;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
import java.util.Map.Entry;
import java.util.Map;
import java.util.Set;

public abstract class cq implements cg {
    static class a extends dp {
        private a() {

        }

        public void a(df arg1, cg arg2) throws cm {
            this.b(arg1, ((cq) arg2));
        }

        public void a(df arg3, cq arg4) throws cm {
            arg4.b = null;
            arg4.a = null;
            arg3.j();
            da v0 = arg3.l();
            arg4.a = arg4.a(arg3, v0);
            if (arg4.a != null) {
                arg4.b = arg4.a(v0.c);
            }

            arg3.m();
            arg3.l();
            arg3.k();
        }

        public void b(df arg3, cq arg4) throws cm {
            if (arg4.a() != null && arg4.c() != null) {
                arg3.a(arg4.e());
                arg3.a(arg4.c(arg4.b));
                arg4.c(arg3);
                arg3.c();
                arg3.d();
                arg3.b();
                return;
            }

            throw new dg("Cannot write a TUnion with no set value!");
        }

        public void b(df arg1, cg arg2) throws cm {
            this.a(arg1, ((cq) arg2));
        }
    }

    static class b implements do0 {
        private b() {

        }

        public a a() {
            return new a();
        }

        public dn b() {
            return this.a();
        }
    }

    static class c extends dq {
        private c() {

        }

        public void a(df arg1, cg arg2) throws cm {
            this.b(arg1, ((cq) arg2));
        }

        public void a(df arg3, cq arg4) throws cm {
            arg4.b = null;
            arg4.a = null;
            short v0 = arg3.v();
            arg4.a = arg4.a(arg3, v0);
            if (arg4.a != null) {
                arg4.b = arg4.a(v0);
            }
        }

        public void b(df arg3, cq arg4) throws cm {
            if (arg4.a() != null && arg4.c() != null) {
                arg3.a(arg4.b.a());
                arg4.d(arg3);
                return;
            }

            throw new dg("Cannot write a TUnion with no set value!");
        }

        public void b(df arg1, cg arg2) throws cm {
            this.a(arg1, ((cq) arg2));
        }
    }

    static class d implements do0 {

        private d() {

        }

        public c a() {
            return new c();
        }

        public dn b() {
            return this.a();
        }
    }

    protected Object a;
    protected cn b;
    private static final Map<Class<? extends dn>, do0> c;

    static {
        HashMap v0 = new HashMap();
        c = ((Map) v0);
        ((Map) v0).put(dp.class, new b());
        c.put(dq.class, new d());
    }

    protected cq() {

        this.b = null;
        this.a = null;
    }

    protected cq(cn arg1, Object arg2) {

        this.a(arg1, arg2);
    }

    protected cq(cq arg3) {

        if (!arg3.getClass().equals(this.getClass())) {
            throw new ClassCastException();
        }

        this.b = arg3.b;
        this.a = cq.a(arg3.a);
    }

    public void a(cn arg1, Object arg2) {
        this.b(arg1, arg2);
        this.b = arg1;
        this.a = arg2;
    }

    private static Object a(Object arg1) {
        if ((arg1 instanceof cg)) {
            return ((cg) arg1).p();
        } else if ((arg1 instanceof ByteBuffer)) {
            return ch.d(((ByteBuffer) arg1));
        } else if ((arg1 instanceof List)) {
            return cq.a(((List) arg1));
        } else if ((arg1 instanceof Set)) {
            return cq.a(((Set) arg1));
        } else if ((arg1 instanceof Map)) {
            return cq.a(((Map) arg1));
        }

        return arg1;
    }

    private static List a(List arg3) {
        ArrayList v0 = new ArrayList(arg3.size());
        Iterator v1 = arg3.iterator();
        while (v1.hasNext()) {
            ((List) v0).add(cq.a(v1.next()));
        }

        return ((List) v0);
    }

    private static Set a(Set arg3) {
        HashSet v0 = new HashSet();
        Iterator v1 = arg3.iterator();
        while (v1.hasNext()) {
            ((Set) v0).add(cq.a(v1.next()));
        }

        return ((Set) v0);
    }

    private static Map a(Map arg4) {
        HashMap v1 = new HashMap();
        Iterator v2 = arg4.entrySet().iterator();
        while (v2.hasNext()) {
            Object v0 = v2.next();
            ((Map) v1).put(cq.a(((Map.Entry) v0).getKey()), cq.a(((Map.Entry) v0).getValue()));
        }

        return ((Map) v1);
    }

    public cn a() {
        return this.b;
    }

    protected abstract cn a(short arg1);

    public Object a(int arg2) {
        return this.a(this.a(((short) arg2)));
    }

    public Object a(cn arg4) {
        if (arg4 != this.b) {
            throw new IllegalArgumentException("Cannot get the value of field " + arg4 + " because union's set field is " + this.b);
        }

        return this.c();
    }

    protected abstract Object a(df arg1, da arg2) throws cm;

    protected abstract Object a(df arg1, short arg2) throws cm;

    public void a(int arg2, Object arg3) {
        this.a(this.a(((short) arg2)), arg3);
    }

    public void a(df arg3) throws cm {
        cq.c.get(arg3.D()).b().b(arg3, ((cg) this));
    }

    protected abstract void b(cn arg1, Object arg2) throws ClassCastException;

    public final void b() {
        this.b = null;
        this.a = null;
    }

    public void b(df arg3) throws cm {
        cq.c.get(arg3.D()).b().a(arg3, ((cg) this));
    }

    public boolean b(cn arg2) {
        boolean v0 = this.b == arg2 ? true : false;
        return v0;
    }

    public Object c() {
        return this.a;
    }

    protected abstract da c(cn arg1);

    protected abstract void c(df arg1) throws cm;

    public boolean c(int arg2) {
        return this.b(this.a(((short) arg2)));
    }

    protected abstract void d(df arg1) throws cm;

    public boolean d() {
        boolean v0 = this.b != null ? true : false;
        return v0;
    }

    protected abstract dk e();

    public String toString() {
        StringBuilder v1 = new StringBuilder();
        v1.append("<");
        v1.append(this.getClass().getSimpleName());
        v1.append(" ");
        if (this.a() != null) {
            Object v0 = this.c();
            v1.append(this.c(this.a()).a);
            v1.append(":");
            if ((v0 instanceof ByteBuffer)) {
                ch.a(((ByteBuffer) v0), v1);
            } else {
                v1.append(v0.toString());
            }
        }

        v1.append(">");
        return v1.toString();
    }
}

